package com.snopy.item.service.impl;

import com.github.pagehelper.PageHelper;
import com.snopy.item.mapper.ItemsCommentsMapperCustom;
import com.snopy.item.pojo.vo.MyCommentVO;
import com.snopy.item.service.ItemCommentsService;
import com.snopy.pojo.PagedGridResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author snopy
 * @version 1.0.0
 * @classname ItemCommentsServiceImpl
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/09 14:31
 */
@Slf4j
@RestController
public class ItemCommentsServiceImpl implements ItemCommentsService {
    @Autowired
    private ItemsCommentsMapperCustom itemsCommentsMapperCustom;


    /**
     * 我的评价查询 分页
     *
     * @param userId
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PagedGridResult queryMyComments(@RequestParam("userId") String userId,
                                           @RequestParam(value = "page",required = false) Integer page,
                                           @RequestParam(value = "pageSize",required = false) Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);

        PageHelper.startPage(page, pageSize);
        List<MyCommentVO> list = itemsCommentsMapperCustom.queryMyComments(map);

        return PagedGridResult.setterPagedGrid(list, page);
    }
    /**
     * @Description 保存评论信息
     * @param: map
     * @Date 2022-03-09
     * @Author txl77912204@gmail.com
     **/
    @Override
    public void saveComments(@RequestBody Map<String, Object> map) {
        itemsCommentsMapperCustom.saveComments(map);
    }
}
